<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title></title>
	<meta name="keywords" content="">
	<meta name="description" content="">
	<link rel="shortcut icon" href="favicon.ico">
	<link th:href="@{/css/bootstrap.min.css}" rel="stylesheet"/>
	<link th:href="@{/css/layui.css}" rel="stylesheet" >
	<link th:href="@{/css/font-awesome.css}" rel="stylesheet"/>
	<!-- bootstrap-table 表格插件样式 -->
	<link th:href="@{/ajax/libs/bootstrap-table/bootstrap-table.min.css}" rel="stylesheet"/>
	<link th:href="@{/ajax/libs/jqTreeGrid/jquery.treegrid.css}" rel="stylesheet"/>
	<link th:href="@{/css/animate.css}" rel="stylesheet"/>
	<link th:href="@{/css/style.css}" rel="stylesheet"/>
	<link th:href="@{/css/checkbox.css}" rel="stylesheet"/>
	<link th:href="@{/ajax/libs/select/select2.css}" rel="stylesheet"/>
	<link th:href="@{/ruoyi/css/ry-ui.min.css}" rel="stylesheet"/>
	<!-- Data Tables -->
	<link th:href="@{/css/plugins/dataTables/dataTables.bootstrap.css}" rel="stylesheet">
	<link href="/ajax/libs/jquery-layout/jquery.layout-latest.css" th:href="@{/ajax/libs/jquery-layout/jquery.layout-latest.css}" rel="stylesheet"/>
	<link href="/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css" th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet"/>
</head>
<body class="gray-bg">
<div class="container-div ui-layout-center">
	<div class="row">
		<div class="col-sm-12 select-info">
			<form id="user-form">
				<div class="select-list gd">
					<ul>
						<li>
							登录状态：<select id="status" name="status">
							<option >所有</option>
							<option >成功</option>
							<option >失败</option>
						</select>
						</li>
						<li class="time">
							<label>登录时间： </label>
							<input type="text" class="form-control layer-date" id="start" placeholder="开始时间" name="params[beginTime]" autocomplete="off"/>
							<span>-</span>
							<input type="text"  class="form-control layer-date" id="end" placeholder="结束时间" name="params[endTime]" autocomplete="off"/>
						</li>
						<li>
							<a class="btn btn-primary btn-rounded btn-sm" onclick="searchUser()"><i class="fa fa-search"></i>&nbsp;搜索</a>
						</li>
					</ul>
				</div>
			</form>
		</div>
		<div class="col-sm-12 select-info table-bordered">
			<div class="btn-group hidden-xs" id="toolbar" role="group" style="margin-bottom: 5px ;margin-top: 10px">
				<a class="btn btn-outline btn-danger btn-rounded" onclick="resetPwd()">
					<i class="fa fa-trash-o"></i> 删除
				</a>
			</div>
			<table id="tb_departments">
			</table>
		</div>
	</div>
</div>
</div>
</div>
</div>
</div>
<script th:src="@{/js/jquery.min.js}"></script>
<script th:src="@{/js/bootstrap.min.js}"></script>
<!-- bootstrap-table 表格插件 -->
<script th:src="@{/ajax/libs/bootstrap-table/bootstrap-table.min.js}"></script>
<script th:src="@{/ajax/libs/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}"></script>
<script th:src="@{/ajax/libs/bootstrap-table/extensions/mobile/bootstrap-table-mobile.min.js}"></script>
<script th:src="@{/ajax/libs/bootstrap-table/extensions/toolbar/bootstrap-table-toolbar.min.js}"></script>
<!-- jquery-export 表格导出插件 -->
<script th:src="@{/ajax/libs/bootstrap-table/extensions/export/bootstrap-table-export.js}"></script>
<script th:src="@{/ajax/libs/bootstrap-table/extensions/export/tableExport.js}"></script>
<!-- Data Tables -->
<script th:src="@{/js/plugins/dataTables/jquery.dataTables.js}"></script>
<script th:src="@{/js/plugins/dataTables/dataTables.bootstrap.js}"></script>
<script th:src="@{/js/plugins/jeditable/jquery.jeditable.js}"></script>
<script th:src="@{/js/plugins/layer/laydate/laydate.js}"></script>
<script th:src="@{/ajax/libs/jquery-layout/jquery.layout-latest.js}"></script>
<script th:src="@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
<script th:src="@{/ajax/libs/layer/layer.min.js}"></script>
<script th:src="@{/ajax/libs/layui/layui.js}"></script>
<script th:src="@{/ruoyi/js/common.js?v=2.2.0}"></script>
<script th:src="@{/ruoyi/js/yuyu-ui.min.js?v=2.2.0}"></script>
<script>
    $(function () {
        initTable();
    });
    function refreshTable() {
        $("#tb_departments").bootstrapTable('refresh',{url : "/user/list"});
    }
    function initTable() {
        //1.初始化Table
        var oTable = new TableInit();
        oTable.Init();

        //2.初始化Button的点击事件
        var oButtonInit = new ButtonInit();
        oButtonInit.Init();
    }
    var TableInit = function () {
        var oTableInit = new Object();
        //初始化Table
        oTableInit.Init = function () {
            $('#tb_departments').bootstrapTable({
                url: '/online/list',         //请求后台的URL（*）
                method: 'get',                      //请求方式（*）
                toolbar: '#toolbar',                //工具按钮用哪个容器
                striped: true,                      //是否显示行间隔色
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,                   //是否显示分页（*）
                sortName: "id",
                sortable: false,                     //是否启用排序
                sortOrder: "asc",                   //排序方式
                queryParams: oTableInit.queryParams,//传递参数（*）
                sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber:1,                       //初始化加载第一页，默认第一页
                pageSize: 10,                       //每页的记录行数（*）
                pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
                search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                strictSearch: true,
                showColumns: true,                  //是否显示所有的列
                showRefresh: true,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                // height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId: "id",                     //每一行的唯一标识，一般为主键列
                showToggle:true,                    //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: false,                   //是否显示父子表
                columns: [{
                    checkbox: true
                } ,{
                    field: 'id',
                    title: '序号',
                    sortable: true
                },{
                    field: 'onlineSessionId',
                    title: '会话编号'
                },{
                    field: 'onlineUsername',
                    title: '用户名称'
                }, {
                    field: 'onlineIp',
                    title: '主机'
                }, {
                    field: 'onlineSystem',
                    title: '操作系统'
                }, {
                    field: 'onlineBrowser',
                    title: '浏览器'
                },
                    {
                        field: 'loginTime',
                        title: '登录时间',
                        formatter: function(e ,value, row, index){
                            var  actions = [];
                            actions.push('  <div type="text">'+formattime(value.loginTime)+'</div>')
                            return actions.join('');
                        }
                    },
                    {
                        field: 'sessionStatus',
                        title: '当前状态',
                        formatter: function(e ,value, row, index){
                            var  actions = [];
                            if (value.sessionStatus == 1){
                                actions.push('<div  type="text" class="btn btn-primary btn-rounded btn-xs">在线</div>');
                            }else {
                                actions.push('<div type="text" class="btn btn-danger btn-rounded btn-xs">退出</div>');
                            }
                            return actions.join('');
                        }
                    },{
                        field: 'Button',
                        title: '操作',
                        align: 'center',
                        events: operateEvents,
                        formatter: Oper
                    }
                    ,],
                showExport:true,              //是否显示导出按钮(此方法是自己写的目的是判断终端是电脑还是手机,电脑则返回true,手机返回falsee,手机不显示按钮)
                exportDataType: "all",              //basic', 'all', 'selected'.
                exportTypes:[ 'excel','doc','xlsx','csv', 'txt', 'sql' ],	    //导出类型
                // exportButton: $('#btn_export'),     //为按钮btn_export  绑定导出事件  自定义导出按钮(可以不用)
                exportOptions:{
                    ignoreColumn: [0,8],            //忽略某一列的索引
                    fileName: '登录日志信息表',              //文件名称设置
                    worksheetName: 'Sheet1',          //表格工作区名称
                    tableName: '数据表',
                    excelstyles: ['background-color', 'color', 'font-size', 'font-weight'],
                    //onMsoNumberFormat: DoOnMsoNumberFormat
                }
            });
        };
        //得到查询的参数
        oTableInit.queryParams = function (params) {
            var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                limit: params.limit,   //页面大小
                offset: params.offset,  //页码
                departmentname: $("#txt_search_departmentname").val(),
                statu: $("#txt_search_statu").val(),
                search:params.search
            };
            return temp;
        };
        return oTableInit;
    };
    function Oper(e ,value, row, index){
        var  actions = [];
        if (value.sessionStatus == 1){
            actions.push('<button id="TableEditor"  type="button" class="btn btn-danger  btn-xs"><i class="fa fa-sign-out"></i>&nbsp强退</button>');
		}
        return actions.join("");
    }
    window.operateEvents = {
        "click #TableEditor": function (e ,value, row, index) {
            layer.confirm('确定下线'+row.onlineUsername+'这个用户吗?', {
                title: "系统提示",
                btn: ['确定','取消'] //按钮
            }, function(){
                $.ajax({
                url:"/forcelogout/"+row.onlineSessionId,
                type: "get",
                contentType:"application/json",
                success: function (data) {
                      if (data.code==200){
                          $("#tb_departments").bootstrapTable('refresh',{url : "/online/list"});
                          layer.msg('下线成功', {icon: 1});
					  }
                }
            });
                }, function(){});
        }};
    function formattime(timestamp) {
        var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
        Y = date.getFullYear() + '-';
        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        D = date.getDate() + ' ';
        h = date.getHours() + ':';
        m = date.getMinutes() + ':';
        s = date.getSeconds();
        return Y+M+D+h+m+s;
    }
    var ButtonInit = function () {
        var oInit = new Object();
        var postdata = {};
        oInit.Init = function () {
            //初始化页面上面的按钮事件
        };
        return oInit;
    };
    $('body').layout({ west__size: 185 });
    //日期范围限制
    var start = {
        elem: '#start',
        format: 'YYYY-MM-DD hh:mm:ss',
        max: '2099-06-16 23:59:59', //最大日期
        istime: true,
        istoday: true,
        choose: function (datas) {
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas //将结束日的初始值设定为开始日
            //获取日期的内容
        }
    };
    var end = {
        elem: '#end',
        format: 'YYYY-MM-DD hh:mm:ss',
        min: laydate.now(),
        max: '2099-06-16 23:59:59',
        istime: true,
        istoday: true,
        choose: function (datas) {
            start.max = datas; //结束日选好后，重置开始日的最大日期
        }
    };
    laydate(start);
    laydate(end);
    /*删除*/
    function resetPwd() {
        var selectedData= $("#tb_departments").bootstrapTable('getSelections');
        var json=JSON.stringify(selectedData);
        if (selectedData == ""){
            layer.alert('请至少选择一条记录!', {
                icon: 3
            })
        }else {
            layer.confirm('确定删除这'+selectedData.length+'个员工信息吗?', {
                btn: ['确定','取消'] //按钮
            }, function(){
                $.ajax({
                    url: '/online/delete',
                    type: 'post',
                    data: json,
                    dataType: 'json',
                    contentType:"application/json",
                    success: function (data) {
                        if (data.code==200) {
                            $("#tb_departments").bootstrapTable('refresh',{url : "/online/list"});
                            layer.msg('删除成功', {icon: 1});
                        }
                    }
                });
            }, function(){});
        }

    }
</script>
</body>
</html>